﻿using System;
using System.Collections.Generic;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class GetRefreshAccessTokenCommand : HttpRequestCommand
    {
        /// <summary>
        /// 
        /// </summary>
        public String ClientID { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public String ClientSecret { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public String RedirectUrl { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public String RefreshToken { get; private set; }

        public GetRefreshAccessTokenCommand(String clientID, String clientSecret, String redirectUrl, String refreshToken)
            : base("https://oauth.live.com/token")
        {
            this.ClientID = clientID;
            this.ClientSecret = clientSecret;
            this.RedirectUrl = redirectUrl;
            this.RefreshToken = refreshToken;

            this.SetProperty();
        }

        private void SetProperty()
        {
            Dictionary<String, String> d = new Dictionary<string, string>();
            d["client_id"] = this.ClientID;
            d["client_secret"] = this.ClientSecret;
            d["refresh_token"] = this.RefreshToken;
            d["redirect_uri"] = this.RedirectUrl;
            d["grant_type"] = "refresh_token";

            this.MethodName = HttpMethodName.Post;
            this.SetBodyStream(new HttpBodyFormUrlEncodedData(d));
        }
        
    }
}
